import {
  GET_WORKORDER_LIST,
  SEND_REQUEST,
  RESPONSE_SUCCESS
} from './mutationTypes';
import { getWorkOrderList } from '../../api/itopApi';

export default {
  async getWorkOrderList({ commit, state }) {
    commit(SEND_REQUEST);
    try {
      let res = await getWorkOrderList(state.searchParams);
      let workOrderList = [];
      let totalCount = 0;
      if (res && res.list) {
        workOrderList = res.list;
        totalCount = res.total;
      }
      commit(GET_WORKORDER_LIST, { workOrderList, totalCount });
      commit(RESPONSE_SUCCESS);
    } catch (e) {}
  }
};
